package com.poorstu.dao.impl;

import java.util.ArrayList;
import java.util.List;

import com.common.base.dao.impl.BaseDaoImpl;
import com.common.base.model.PaginationSupport;
import com.poorstu.dao.LoginDao;
import com.poorstu.model.LeaseMod;
import com.poorstu.model.LoginMod;
import com.poorstu.model.PowerMod;
import com.poorstu.model.RoleMod;

public class LoginImpl extends BaseDaoImpl implements LoginDao {

	public List<LoginMod> select(LoginMod login) {
		return super.findByNamedQuery(login.getName());
	}

	public LoginMod selectUserById(int allUserId) {
		List a = super.findByHql("from LoginMod where id="+allUserId);
		
		return (LoginMod)a.get(0);
	}

	public List<LoginMod> selectUserAll() {
		
		return super.findAll("LoginMod");
	}

	public boolean menberAdd(LoginMod login) {
		
		try{
			super.save(login);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		
	}

	public boolean menberUpdate(LoginMod login) {
	
		try{
		 super.merge(login);
		 return true;
		}catch(Exception e ){
			e.printStackTrace();
			return false;
		}
	}

	public boolean menberDelete(List<LoginMod> login) {
		try{
			super.deleteAll(login);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}

	public LoginMod getUserByUserAccount(String userAccount) {
		try{
			return (LoginMod)super.findByHql("from LoginMod where userAccount = " + userAccount).get(0);
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}

	public PaginationSupport getUserByPage(String where,
			String orderField, String order, Integer startIndex,
			Integer pageSize) {
		PaginationSupport ps;
		try{
			ps = super.findByWhereOrderBy(LoginMod.class.getName(), where, orderField, order, startIndex, pageSize);
		}
		catch(Exception e)
		{
			e.printStackTrace();
			return null;
			
		}
		return ps;
	}

	public boolean changePwd(LoginMod login) {
		try{
		 super.merge(login);
		return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}

	public boolean excelInput(ArrayList<LoginMod> loginList) {
		
		try{
			super.saveOrUpdate(loginList);
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}

	
	
	
	}
	
	

